const service = require('../service/messageService')
const controller = {
  // 添加
  async addMessage (req, res) {
    const { message, username, email } = req.body
    let data = await service.addMessage(message, username, email)
    res.send({ ok: 1, data })
  },

  // 删除
  async delAll (req, res) {
    const { ids } = req.body
    let data = await service.delAll(ids)
    res.send({ ok: 1, data })
  },

  // 获取
  async findMessage (req, res) {
    let { page, limit, message, email, username } = req.query
    page = page ? page : 1
    limit = limit ? limit : 8
    message = message ? new RegExp(message) : new RegExp('.')
    email = email ? new RegExp(email) : new RegExp('.')
    username = username ? new RegExp(username) : new RegExp('.')
    let data = await service.findMessage(page, limit, { message, email, username })

    res.send({ ok: 1, inof: data })
  }
}
module.exports = controller